<?php
    // Error Reporting

    error_reporting(E_ALL);
    ini_set("display_errors", "on");

    //header('Content-type: image/gif');

    include('lzw.php');
    foreach($_GET as $key => $value) {
        $params = decompress(base64_decode($key));
        break;
    }
    $params = explode("&", $params);
    $finalParams = array();
    foreach($params as $param) {
        $paramArr = explode("=", $param);
        $finalParams[$paramArr[0]] = $paramArr[1];
    }
    $error = urldecode($finalParams['error']);
    $customer_id = htmlentities($finalParams['trk_id']);
    $date = getdate();
    $day = $date["mday"];
    $month = $date["mon"];
    if ($date["hours"] == 0) {
        $date = getdate(strtotime("-1 day"));
        $day = $date["mday"];
        $month = $date["mon"];
    }
    if ($day < 10) {
        $day = "0".$day;
    }
    if ($month < 10) {
        $month = "0".$month;
    }
    $dateForFile = $date["year"]."-".$month."-".$day;
    if (!is_dir("data/errors/".$dateForFile)) {
        mkdir("data/errors/".$dateForFile);
    }
    $filename = $customer_id.".txt";
    $flatHandler = fopen("data/errors/".$dateForFile."/".$filename, "a");

    fwrite($flatHandler, $error."\n");
    fclose($flatHandler);

    //include('http://trakk247.com/tm_pixel.gif');
?>
